﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ini;

namespace Sequence
{
    public partial class FrmOptions : Form
    {
        private IniFile oIni = new IniFile("C:\\Sapiens\\Sequence\\Sequence.ini");
        public FrmOptions()
        {
            InitializeComponent();
        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void FrmOptions_Load(object sender, EventArgs e)
        {
            LoadGroup(grSettings);
            LoadGroup(grMQ);
            LoadGroup(grQDHeader);
            LoadGroup(grWebServices);
        }

        private void LoadGroup(GroupBox oGr)
        {
            foreach (Control oCon in oGr.Controls)
            {
                if ( oCon.Name.Substring(0,3) == "txt")
                    oCon.Text = oIni.IniReadValue(oGr.Text, oCon.Name.Replace("txt", ""), "");
            }
        }

        private void cmdOk_Click(object sender, EventArgs e)
        {
            SaveGroup(grSettings);
            SaveGroup(grMQ);
            SaveGroup(grQDHeader);
            SaveGroup(grWebServices);
            this.Close();
        }

        private void SaveGroup(GroupBox oGr)
        {
            foreach (Control oCon in oGr.Controls)
            {
                if (oCon.Name.Substring(0, 3) == "txt")
                    oIni.IniWriteValue(oGr.Text, oCon.Name.Replace("txt", ""), oCon.Text);
            }
        }

        private void txtCommunication_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (txtCommunication.Text == "MQ")
            {
                txtQueueManager.Enabled = true;
                txtChannel.Enabled  = true;
                txtServer.Enabled  = true;
                txtRequestQueue.Enabled  = true;
                txtResponseQueue.Enabled  = true;
            }
            else
            {
                txtQueueManager.Enabled = false;
                txtChannel.Enabled  = false;
                txtServer.Enabled  = false;
                txtRequestQueue.Enabled  = false;
                txtResponseQueue.Enabled  = false;                
            }
            txtUrl.Enabled = !txtResponseQueue.Enabled;
        }    
    }
}
